package com.funong.matrix.core.utils;

import org.kie.api.KieBase;
import org.kie.api.io.Resource;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.utils.KieHelper;

public class DroolsUtil {
    public static void run(String ruleName, ContractApproveBizInfoDTO bizParameter) {
        System.out.println("drools Test start ");

        //DROOLS文件加载模式
        KieHelper helper = new KieHelper();
        Resource resource = ResourceFactory.newClassPathResource(ruleName, "UTF-8");
        helper.addResource(resource);
        KieBase kieBase = helper.build();
        KieSession kieSession = kieBase.newKieSession();

        kieSession.insert(bizParameter);

        int count = kieSession.fireAllRules();

        kieSession.dispose();
        System.out.println("drools Test end ");
    }

    public static void run2(String ruleName, ContractApproveBizInfoDTO bizParameter) {
        System.out.println("drools Test start ");

        //DROOLS文件加载模式
        KieHelper helper = new KieHelper();
        //Resource resource = ResourceFactory.newClassPathResource(ruleName, "UTF-8");
        //helper.addResource(resource);
        helper.addContent(ruleName, ResourceType.DRL);
        KieBase kieBase = helper.build();
        KieSession kieSession = kieBase.newKieSession();

        kieSession.insert(bizParameter);



        int count = kieSession.fireAllRules();

        kieSession.dispose();
        System.out.println("drools Test end ");
    }

}
